<table>
    <tbody>
        <tr>
            <td width="100px" class="top"><?php echo $form->label("MessageSent.receiver", "Send to") ?></td>
            <td>
                <?php echo $form->radio('MessageSent.receiver', array(ITS_PREFIX => 'ITS', SUPPLIER_PREFIX => 'Vendor'), array('legend' => false)); ?><br />
                <?php echo $form->hidden("MessageSent.receiver_id"); ?>
                <?php echo $form->select("MessageSent.supplier_id", $suppliers); ?>
            </td>
        </tr>
        <tr>
            <td><?php echo $form->label("MessageSent.send_to", "Attn.") ?></td>
            <td><?php echo $form->text("MessageSent.send_to") ?> </td>
        </tr>
        <tr>
            <td><?php echo $form->label("MessageSent.subject", "Subject") ?></td>
            <td>
                <?php echo $form->text("MessageSent.subject", array('size' => 60)) ?>
            </td>
        </tr>
    </tbody>
</table>
<script type="text/javascript">
    $j(function() {
        // การเลือก send to ว่า Supplier / ITS
        $j(":radio[id*=Receiver]").bind('change', function() {
            if ($j(this).is(':checked')) {
                var receiver = $j(this).val();
            } else {
                var receiver = null;
            }
            $j('#MessageSentSupplierId').hide();
            if (receiver == 'its') {
                $j('#MessageSentReceiverId').val('');
            } else if (receiver == 'supplier') {
                $j('#MessageSentSupplierId').show().change();
            }
        }).change();

        // กำหนด receiver_id ตาม ผู้รับ Supplier/Customer
        $j('#MessageSentSupplierId').bind('change', function() {
            var receiver_id = $j(this).val();
            $j('#MessageSentReceiverId').val(receiver_id);
        });
    })
</script>

